package com.tbit.uqbike.webmanager.util;

import com.tbit.uqbike.constant.MachinePosConstant;
import com.tbit.uqbike.constant.enums.RechargeType;
import com.tbit.uqbike.object.pojo.*;
import com.tbit.uqbike.object.value.UserRcDetail;
import com.tbit.utils.DateTimeUtil;
import com.tbit.utils.DoubleUtils;
import org.springframework.web.servlet.support.RequestContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 续费导出
 *
 * @author Leon
 * 2015-6-10 下午02:34:54
 */
public class RechargeExportUtil {

    /**
     * 续费数据导出
     */
    public static List<String[]> getExportContent(List<StatPark> list, RequestContext context) {
        List<String[]> result = new ArrayList<>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_time"), context.getMessage("excel_head_ridelog_total"), context.getMessage("excel_head_ridelog_sum")};
        result.add(title);
        for (StatPark e : list) {
            String[] content = {e.getName(), String.valueOf(DoubleUtils.doubleScale(e.getMoney() * 1.0 / 100.0)), String.valueOf(e.getTotal())};
            result.add(content);
        }


        return result;
    }

    /**
     * 车辆数据导出
     */
    public static List<String[]> getMachineExportContent(List<MachineBaseInfo> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();

        /*标题*/
        String[] title = {context.getMessage("excel.col.machineNO"), context.getMessage("excel.col.userCode"),"车辆类型",
                context.getMessage("excel.col.frame"), context.getMessage("excel.col.license"), context.getMessage("excel.col.motor"),
                "头盔Mac地址",
                context.getMessage("excel_head_machine_status"),"标签名称","电池编号", context.getMessage("excel_head_machine_battery_solution"),
                context.getMessage("excel_head_machine_addTime"), context.getMessage("excel_head_machine_owned_operator"),
                context.getMessage("excel_head_ridelog_remark"), "所属分组"};
        result.add(title);
        for (MachineBaseInfo m : list) {
            StringBuffer stringBuffer = new StringBuffer();
            if (m.getState().equals(MachinePosConstant.MACHINE_STATE_PEND)) {
                stringBuffer.append(context.getMessage("excel_head_machine_pending"));
            } else if (m.getState().equals(MachinePosConstant.MACHINE_STATE_DISPATCH)) {
                stringBuffer.append(context.getMessage("excel_head_machine_scheduled"));
            } else if (m.getState().equals(MachinePosConstant.MACHINE_STATE_NORMAL)) {
                stringBuffer.append(context.getMessage("excel_head_machine_normal_operation"));
            } else if (m.getState().equals(MachinePosConstant.MACHINE_STATE_FAULT)) {
                stringBuffer.append(context.getMessage("excel_head_machine_malfunction"));
            } else if (m.getState().equals(MachinePosConstant.MACHINE_STATE_SCRAP)) {
                stringBuffer.append(context.getMessage("excel_head_machine_scrapped"));
            }
            String[] content = {m.getMachineNO(), m.getUserCode(),m.getMachineType() == 0?"电单车":"自行车", m.getFrame(), m.getLicense(), m.getMotor(), m.getHelmetMac(), stringBuffer.toString(),m.getTagName(),m.getBatteryNO(), m.getBatteryName(),
                    DateTimeUtil.DateTimeToString(m.getJoinTime()), m.getAccountName(), m.getRemark(), m.getGroupName()};
            result.add(content);
        }


        return result;
    }

    /**
     * 订单数据导出
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> getRechargeExportContent(List<RideLog> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();

        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_number"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel.col.machineNO"), context.getMessage("excel.col.userCode"), context.getMessage("excel_head_ridelog_car_rental_site"), context.getMessage("excel_head_ridelog_drop_off_site"), context.getMessage("excel_head_ridelog_startTime"), context.getMessage("excel_head_ridelog_finishTime"), context.getMessage("excel_head_ridelog_parkTime"), context.getMessage("excel_head_ridelog_mileage"), context.getMessage("excel_head_ridelog_total_cost"), context.getMessage("excel_head_ridelog_payTime"), context.getMessage("excel_head_ridelog_remark")};
        result.add(title);
        for (RideLog rideLog : list) {
            String[] content = {rideLog.getOrderNO(), rideLog.getPhone(), rideLog.getMachineNO(), rideLog.getUserCode(), rideLog.getStartName(), rideLog.getEndName(), DateTimeUtil.DateTimeToString(rideLog.getStartTime()), DateTimeUtil.DateTimeToString(rideLog.getEndTime()), String.valueOf(rideLog.getStopTime()), String.valueOf(rideLog.getMileage()), String.valueOf((double) rideLog.getMoney() / 100),
                    DateTimeUtil.DateTimeToString(rideLog.getPayTime()), rideLog.getRemark()};
            result.add(content);
        }
        return result;
    }

    /**
     * 骑行卡数据导出
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> rideCardContent(List<UserRcDetail> list, RequestContext context) {
        List<String[]> result = new ArrayList<>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_number"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_ridelog_purchase_time"), context.getMessage("excel_head_ridecard_name"), "骑行卡有效天数", context.getMessage("excel_head_money_total")};
        result.add(title);
        for (UserRcDetail userRcDetail : list) {
            String[] tmp = {context.getMessage("excel_head_ridecard_day"), context.getMessage("excel_head_ridecard_week"), context.getMessage("excel_head_ridecard_month"), context.getMessage("excel_head_ridecard_season"), context.getMessage("excel_head_ridecard_semi_annual"), context.getMessage("excel_head_ridecard_year")};
            String[] content = {userRcDetail.getOrderNO(), userRcDetail.getPhone(), DateTimeUtil.DateTimeToString(userRcDetail.getBuyTime()), userRcDetail.getName(), userRcDetail.getVaildDays()+"", String.valueOf(userRcDetail.getMoney() * 1.0 / 100)};
            result.add(content);
        }
        return result;
    }

    /**
     * 押金变动
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> depositContent(List<WeixinDepositLog> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_deposit_order"), context.getMessage("excel_head_deposit_return_order"), context.getMessage("excel_head_total"), context.getMessage("excel_head_deposit_is_return"), context.getMessage("excel_head_deposit_returnTime"), context.getMessage("excel_head_ridelog_remark")};
        result.add(title);
        for (WeixinDepositLog weixinDepositLog : list) {
            String[] content = {weixinDepositLog.getPhone(), weixinDepositLog.getOut_trade_no(), weixinDepositLog.getOut_refund_no()
                    , String.valueOf(weixinDepositLog.getDepositMoney() * 1.0 / 100), weixinDepositLog.getIsReturn() == true ? context.getMessage("excel_head_deposit_yes") : context.getMessage("excel_head_deposit_no"), DateTimeUtil.DateTimeToString(weixinDepositLog.getReturnTime()), weixinDepositLog.getRemark()};
            result.add(content);
        }
        return result;
    }

    public static List<String[]> exportDeposit(List<WeixinDepositLog> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_name"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_money_total"), context.getMessage("excel_head_ridelog_payTime"), context.getMessage("excel_head_ridelog_remark")};
        result.add(title);
        for (WeixinDepositLog weixinDepositLog : list) {
            String[] content = {weixinDepositLog.getName(), weixinDepositLog.getPhone(), String.valueOf(weixinDepositLog.getDepositMoney() * 1.0 / 100), DateTimeUtil.DateTimeToString(weixinDepositLog.getAddTime()), weixinDepositLog.getRemark()};
            result.add(content);
        }
        return result;
    }

    /**
     * 用户金额变动
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> userMoneyContent(List<User> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_name"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_over"), context.getMessage("excel_head_recharge_total")};
        result.add(title);
        for (User user : list) {
            String[] content = {user.getName(), user.getPhone(),
                    String.valueOf(user.getMoney() * 1.0 / 100), String.valueOf(user.getRechargeMoney() * 1.0 / 100)};
            result.add(content);
        }
        return result;
    }

    /**
     * 用户充值记录
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> rechargeContent(List<Recharge> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_number"), "运营区域", context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_recharge_total"), context.getMessage("excel_head_recharge_time"), context.getMessage("excel_head_ridelog_payTime"), context.getMessage("excel_head_is_deposit"), context.getMessage("excel_head_ridelog_remark"), context.getMessage("excel_head_ridelog_platform"), "已退金额"};
        result.add(title);
        for (Recharge recharge : list) {
            String[] content = {recharge.getOrderNO(), recharge.getAreaName(), recharge.getPhone(), String.valueOf(recharge.getMoney() * 1.0 / 100),
                    DateTimeUtil.DateTimeToString(new Date(recharge.getRechargeTime())), DateTimeUtil.DateTimeToString(new Date(recharge.getPayTime())), recharge.getDeposit() ? "是" : "不是", recharge.getRemark(), RechargeType.of(recharge.getType()).getDesc(), String.valueOf(recharge.getRefundMoney() * 1.0 / 100)};
            result.add(content);
        }
        return result;
    }

    /**
     * 会员卡导出
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> vipContent(List<UserRcDetail> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {context.getMessage("excel_head_ridelog_number"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_ridelog_purchase_time"), context.getMessage("excel_head_ridecard_name"), context.getMessage("excel_head_ridecard_type"), context.getMessage("excel_head_money_total")};
        result.add(title);
        for (UserRcDetail userRcDetail : list) {
            String[] tmp = {context.getMessage("excel_head_ridelog_number"), context.getMessage("excel_head_ridelog_phone"), context.getMessage("excel_head_ridelog_purchase_time"), context.getMessage("excel_head_ridecard_name"), context.getMessage("excel_head_ridecard_type"), context.getMessage("excel_head_ridecard_total")};
            ;
            String[] content = {userRcDetail.getOrderNO(), userRcDetail.getPhone(), DateTimeUtil.DateTimeToString(userRcDetail.getBuyTime()), userRcDetail.getName(), tmp[userRcDetail.getType()], String.valueOf(userRcDetail.getMoney() * 1.0 / 100)};
            result.add(content);
        }
        return result;
    }

    /**
     * 会员卡导出
     *
     * @param list
     * @param context
     * @return
     */
    public static List<String[]> detailarrearsContent(List<Map<String, Object>> list, RequestContext context) {
        List<String[]> result = new ArrayList<String[]>();
        /*标题*/
        String[] title = {"姓名", "手机号", "总金额"};
        result.add(title);
        for (Map<String, Object> map : list) {
            String[] content = {String.valueOf(map.get("name")), String.valueOf(map.get("phone")), String.valueOf((map.get("totalAmountOwed")))};
            result.add(content);
        }
        return result;
    }

}
